<?php

if ($username)
{
	$getRandomEventStuff = fetch("SELECT * FROM random_events WHERE game = '$game'");

	$get1st = rand(1,400);
	if ($get1st == "5")
	{
		$getPrize = explode(", ", $getRandomEventStuff[point_event]);

		$randPrize = rand(0, count($getPrize) - 1);
		$getPrize = $getPrize[$randPrize];

		if ($getPrize)
		{
		$randomEvent .= "
		<CENTER><TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 WIDTH=300>
	   <TR BGCOLOR=\"$topAndBottomBG\">
	      <TD WIDTH=91 HEIGHT=35>
	         <CENTER><FONT SIZE=\"+2\" COLOR=\"$topAndBottomText\"><B>--Random
	         Event--</B></FONT></CENTER>
	      </TD>
	   </TR>
	   <TR BGCOLOR=\"$maincellColor\">
	      <TD WIDTH=91 HEIGHT=40>
	         <CENTER><FONT SIZE=\"-1\">Congratulations $display_name!<BR>
	         You found $getPrize $pointsVar on the ground!</FONT></CENTER>
	      </TD>
	   </TR>
	</TABLE>
	</CENTER>
		";

		points("$game", "$username", "$getPrize");
		}
	}

	$getitem = rand(1,750);
	if ($getitem == "5")
	{

		$getPrize = explode(", ", $getRandomEventStuff[cheap_item_event]);

		$randPrize = rand(0, count($getPrize) - 1);
		$getPrize = $getPrize[$randPrize];

		$num_pets2 = $num_pets - 1;
		$randPet = rand(0,$num_pets2);
		$findPet = fetch("SELECT * FROM user_pets2 WHERE owner = '$userid' AND game = '$game' ORDER BY id LIMIT $randPet,1");

		if ($findPet[attitude] >= 55)
		{
			$find_item3 = fetch("SELECT * FROM items2 WHERE item_name = '$getPrize' AND game 	= '$game'");

			if ($find_item3[id])
			{
				$findSpecies = fetch("SELECT * FROM pets2 WHERE id = '$findPet[species]' AND game = '$game'");

				$randomEvent .= "
				<CENTER><TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 	WIDTH=350>
			   <TR BGCOLOR=\"$topAndBottomBG\">
			      <TD COLSPAN=2 WIDTH=350 HEIGHT=35>
			         <CENTER><FONT SIZE=\"+2\" COLOR=\"$topAndBottomText\"><B>--$findPet[name] Found Something!--</B></FONT></CENTER>
			      </TD>
			   </TR>
			   <TR BGCOLOR=\"$maincellColor\">
			      <td>
			      <img src=images/user_images/opg_$game/pets/pet_$findSpecies[id].gif>
			      </td>
			      <TD WIDTH=200>
			         <CENTER><FONT SIZE=\"-1\">$findPet[name] found a $getPrize for you!</FONT><br><img 			src=images/user_images/opg_$game/items/item_$find_item3[id].gif></CENTER>
			      </TD>
			   </TR>
			</TABLE>
			</CENTER>
				";

				mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES 		('$userid','$find_item3[id]','$find_item3[parts]','$game')");
			}
		}
	}


	$getTalk = rand(1,900);
	if ($getTalk == "5")
	{
		$sayWhat = explode(", ", $getRandomEventStuff[talking_event]);

		$randSaying = rand(0, count($sayWhat) - 1);
		$getSaying = $sayWhat[$randSaying];

		if ($getSaying)
		{
			$randomEvent .= "
			<CENTER><TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 WIDTH=300>
		   <TR BGCOLOR=\"$topAndBottomBG\">
		      <TD WIDTH=91 HEIGHT=35>
		         <CENTER><FONT SIZE=\"+2\" COLOR=\"$topAndBottomText\"><B>--Random
		         Event--</B></FONT></CENTER>
		      </TD>
		   </TR>
		   <TR BGCOLOR=\"$maincellColor\">
		      <TD WIDTH=91 HEIGHT=40>
		         <CENTER><FONT SIZE=\"-1\">Hey $display_name! $getSaying</FONT></CENTER>
		      </TD>
		   </TR>
		</TABLE>
		</CENTER>
			";
		}
	}

	$getitemRare = rand(1,2500);
	if ($getitemRare == "5")
	{
		$getPrize = explode(", ", $getRandomEventStuff[rare_item_event]);

		$randPrize = rand(0, count($getPrize) - 1);
		$getPrize2 = $getPrize[$randPrize];

		$find_item3 = fetch("SELECT * FROM items2 WHERE item_name = '$getPrize2'");

		if ($find_item3[id])
		{
			$randomEvent .= "
			<CENTER><TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 WIDTH=300>
		   <TR BGCOLOR=\"$topAndBottomBG\">
		      <TD WIDTH=300 HEIGHT=35>
		         <CENTER><FONT SIZE=\"+2\" COLOR=\"$topAndBottomText\"><B>--Random
		         Event--</B></FONT></CENTER>
		      </TD>
		   </TR>
		   <TR BGCOLOR=\"$maincellColor\">
		      <TD WIDTH=300 HEIGHT=40>
		         <CENTER><FONT SIZE=\"-1\">A wizard appears and hands you a $getPrize2 .. it 	looks rare!!</FONT><br><img 	src=images/user_images/opg_$game/items/item_$find_item3[id].gif></CENTER>
		      </TD>
		   </TR>
		</TABLE>
		</CENTER>
			";

			mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES 	('$userid','$find_item3[id]','$find_item3[parts]','$game')");
		}
	}
}

?>